package cn.iocoder.yudao.module.infra.dal.mysql.job;


import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.infra.controller.admin.job.vo.JobExportReqVO;
import cn.iocoder.yudao.module.infra.controller.admin.job.vo.JobPageReqVO;
import cn.iocoder.yudao.module.infra.dal.dataobject.job.Job;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 定时任务 Mapper
 */
@Mapper
public interface JobMapper extends BaseMapperX<Job> {

    default Job selectByHandlerName(String handlerName) {
        return selectOne(Job::getHandlerName, handlerName);
    }

    default PageResult<Job> selectPage(JobPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<Job>()
                .likeIfPresent(Job::getName, reqVO.getName())
                .eqIfPresent(Job::getStatus, reqVO.getStatus())
                .likeIfPresent(Job::getHandlerName, reqVO.getHandlerName())
        );
    }

    default List<Job> selectList(JobExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<Job>()
                .likeIfPresent(Job::getName, reqVO.getName())
                .eqIfPresent(Job::getStatus, reqVO.getStatus())
                .likeIfPresent(Job::getHandlerName, reqVO.getHandlerName())
        );
    }

}
